<template>
  <BasicModal v-bind="$attrs" :width="630" :title="getTitle"
    :canFullscreen="false" :centered="true" :destroyOnClose="true"
    :showCancelBtn="false" :showOkBtn="false"
    :bodyStyle="{ height: '600px', overflow: 'hidden' }"
    @register="registerModal"
  >
    <div style="zoom: 1; padding: 0 10px 10px; margin-top: 10px; " :style="{height:'600px', overflowY:'auto'}">
    <!--引用表格-->
    <BasicTable @register="registerTable" :onRowClick="handleClick" :onRowDbClick="handleDblclick" :rowClassName="rowClassName">
      <!--插槽:table标题-->
      <template #tableTitle>
        <a-button type="primary" color="success" preIcon="ant-design:plus-outlined" @click="handleAdd" v-if="!selectRows.id"> 新增</a-button>
        <a-button type="primary" color="warning" preIcon="ant-design:edit-outlined" @click="handleEdit" v-if="selectRows.id"> 编辑 </a-button>
        <a-button type="primary" color="error" preIcon="ant-design:delete-outlined" @click="handleDelete"> 删除 </a-button>
      </template>
      <!--产品-->
      <template #itemIds="{ text, record }">
        <a-tag color="green" v-if="text" v-for="(item, index) in text.split(',')" style="margin: 5px 10px 5px 0; width: 200px;">
          {{index + 1}} {{item}}
        </a-tag>
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
      </template>
    </BasicTable>
    </div>
  </BasicModal>

  <BankRunningReportSetModal @register="registerModalset" @success="reload"></BankRunningReportSetModal>
</template>

<script lang="ts" name="full-bankRunningReportSet" setup>
  import { ref, computed, unref, reactive } from 'vue';
  import { BasicModal, useModalInner, useModal } from '/@/components/Modal';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns } from '../types/BankRunningReportSet.data';
  import { useMessage } from "/@/hooks/web/useMessage";
  import { list, deleteOne } from '../types/BankRunningReportSet.api';

  import BankRunningReportSetModal from './BankBalanceSetModal.vue';

  const $message = useMessage();

  const getTitle = computed(() => {
    return '系统对账 - 设置';
  });

  //二、初始化数据 -----------------------------------------------------------
  const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
    setModalProps({ confirmLoading: false });
    // let record = data?.record || {};

    // // 判断操作是新增还是修改
    // getTitle.value       = record?.title + " _ " + record?.djm + ' __ 银行余额：' + record.t0lslrje;
    // getTitleSub.value    = record?.title + " _ " + record?.djm ;
    // queryParam.bankId    = record?.bankId;
    // queryParam.beginDate = ''; //dayjs().subtract(2, 'month').startOf('month').format('YYYY-MM-DD'),
    // queryParam.endDate   = record?.endDate;
    // queryParam.insider   = ''; //无差异

    // searchQuery();
  });

  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      api: list,
      canResize: false,
      columns: columns,
      size: 'small',
      showTableSetting: false,
      showIndexColumn: true, //行号
      showActionColumn: false,
      useSearchForm: false,
      pagination: false
    }
  });

  const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;


  //注册model
  const [registerModalset, { openModal }] = useModal();
  /**
   * 新增事件
   */
  function handleAdd() {
    openModal(true, {
      isUpdate: false,
      showFooter: true,
    });
  }

  /**
   * 编辑事件
   */
  function handleEdit(record: Recordable) {
    if (!selectRows.id) {
      $message.createMessage.warning('请选择一条数据');
      return
    }
    record = {
      id: selectRows.id,
    }
    openModal(true, {
      record,
      isUpdate: true,
      showFooter: true,
    });
  }
  /**
   * 详情
   */
  function handleDetail(record: Recordable) {
    openModal(true, {
      record,
      isUpdate: true,
      showFooter: false,
    });
  }
  /**
   * 删除事件
   */
  async function handleDelete(record) {
    await deleteOne({ id: record.id }, reload);
  }
  /**
   * 批量删除事件
   */
  async function batchHandleDelete() {
    //await batchDelete({ ids: selectedRowKeys.value }, reload);
  }
  /**
   * 成功回调
   */
  function handleSuccess({ isUpdate, values }) {
    reload();
  }
  /**
   * 操作栏
   */
  function getTableAction(record) {
    return [
      {
        label: '编辑',
        onClick: handleEdit.bind(null, record),
      },
    ];
  }
  /**
   * 下拉操作栏
   */
  function getDropDownAction(record) {
    return [
      {
        label: '详情',
        onClick: handleDetail.bind(null, record),
      },
      {
        label: '删除',
        popConfirm: {
          title: '是否确认删除',
          confirm: handleDelete.bind(null, record),
        },
      },
    ];
  }

  //双击行
  function handleDblclick(record) {

  }

  //单击行
  let selectRows = reactive<any>({ id: '' });
  function handleClick(record) {
    if (selectRows.id != record.id) {
      selectRows.id = record.id;
    } else {
      selectRows.id = '';
    }
  }

  //定义行样式
  function rowClassName(record, index) {
    let className = '';
    if (record.id === selectRows.id) {
      className = 'row-selected';
    }
    return className;
  }
</script>
<style scoped></style>
